home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / procssng / ccs / ccs-11tl.lha / lbl / hips / sources / rle / htorle.c next >
Encoding:
C/C++ Source or Header  |  1991-09-17  |  2.9 KB  |  130 lines

  1. /*
  2.  * Altered by:    Fritz Renema
  3.  *         Advanced Development Projects Group
  4.  *         Lawrence Berkeley Laboratory
  5.  *
  6.  * reads a byte per pixel HIPS file (with a header)
  7.  * from stdin and converts it to rle format.
  8.  *
  9.  *  updated to use new rle library routines, Brian Tierney,  7/91
  10.  *  converted to HIPS2:  Brian Tierney, 9/91
  11.  */
  12.  
  13. #include <stdio.h>
  14.  
  15. #include <rle.h>
  16. #include <hipl_format.h>
  17.  
  18. /***************************************************************/
  19.  
  20. main(argc, argv)
  21.     int       argc;
  22.     char     *argv[];
  23.  
  24. {
  25.     struct header hd;        /* HIPS header structure */
  26.     char     *iinfo[5];        /* important information */
  27.     char      cols[100], rows[100];    /* number of cols and rows */
  28.  
  29.     if (argc > 1)
  30.     usage(argv[0]);
  31.  
  32.     read_header(&hd);
  33.     if (hd.pixel_format != PFBYTE)
  34.     fatal("%s: input must be byte/pixel format.\n", argv[0]);
  35.  
  36. /* initialize array of important information to be passed to htorle */
  37.  
  38.     sprintf(cols, "%d", hd.ocols);
  39.     sprintf(rows, "%d", hd.orows);
  40.  
  41.     iinfo[0] = "htorle";
  42.     iinfo[1] = cols;
  43.     iinfo[2] = rows;
  44.     iinfo[3] = "HIPS2";
  45.     iinfo[4] = "";
  46.  
  47.     if (htorle(4, iinfo) < 0)
  48.     fatal("Error trying to convert from HIPS to rle.\n");
  49.  
  50.     exit(0);
  51. }
  52.  
  53. usage(prgrm)
  54.     char     *prgrm;
  55. {
  56.     fatal("Usage: %s < infile.hips > outfile.rle", prgrm);
  57. }
  58.  
  59. fatal(msg, ar1, ar2, ar3, ar4, ar5)
  60.     char     *msg;
  61.     int       ar1, ar2, ar3, ar4, ar5;
  62. {
  63.     fprintf(stderr, msg, ar1, ar2, ar3, ar4, ar5);
  64.     exit(-1);
  65. }
  66.  
  67. int
  68. htorle(argc, argv)
  69.     int       argc;
  70.     char     *argv[];
  71. {
  72. /*
  73.  * converted from:
  74.  *    graytorle.c - Create an RLE image from gray pixels.
  75.  *
  76.  * Author:    Michael J. Banks
  77.  *         Computer Science Dept.
  78.  *         University of Utah
  79.  * Date:    Wed Jun 22 1988
  80.  * Copyright (c) 1988, University of Utah
  81.  */
  82.  
  83.     int       xsize, ysize;    /* Image size. */
  84.     int       hsize, hflag = 0;    /* Image header size. */
  85.     int       aflag = 0;    /* Alpha channel flag. */
  86.     int       oflag = 0;    /* Output file flag. */
  87.     int       files;        /* Number of files. */
  88.     char    **fname;        /* List of input file names. */
  89.     char     *oname;        /* Output file name. */
  90.     rle_pixel **outrow;        /* Output buffer. */
  91.     register int row;
  92.     char     *trash;
  93.  
  94.     if (!scanargs(argc, argv,
  95.           "% xsize!d ysize!d h%-hdrsize!d o%-outfile!s a%- files!*s",
  96.           &xsize, &ysize,
  97.           &hflag, &hsize,
  98.           &oflag, &oname,
  99.           &aflag,
  100.           &files, &fname))
  101.     return (-1);
  102.  
  103.     /* Initialize the_hdr and allocate image row storage. */
  104.  
  105.     rle_dflt_hdr.xmax = xsize - 1;
  106.     rle_dflt_hdr.ymax = ysize - 1;
  107.  
  108.     rle_dflt_hdr.ncolors = 1;
  109.     rle_dflt_hdr.ncmap = 0;
  110.     rle_dflt_hdr.cmap = NULL;
  111.     rle_dflt_hdr.cmaplen = 0;
  112.  
  113.     rle_dflt_hdr.rle_file = stdout;
  114.  
  115.     rle_put_setup(&rle_dflt_hdr);
  116.  
  117.     if (rle_row_alloc(&rle_dflt_hdr, &outrow)) {
  118.     fprintf(stderr, "rle row allocation failed!\n");
  119.     return (-2);
  120.     }
  121.     for (row = 0; row < ysize; row++) {
  122.     fread(outrow[0], 1, xsize, stdin);
  123.     rle_putrow(outrow, xsize, &rle_dflt_hdr);
  124.     }
  125.  
  126.     rle_puteof(&rle_dflt_hdr);
  127.  
  128.     return (1);
  129. }
  130.